//Unittest2 updateCoins
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>

int main(int argc, char const *argv[])
{
	int player;
	struct gameState state;
	int bonus;
	int i;
	int j;
	int c;
	int s;
	int g;
	int coin_total;
	int r;

	for(i = 0; i < 1000; i++){
		c = 0;
		s = 0;
		g = 0;
		//create random game state
		for (j = 0; j < sizeof(struct gameState); j++) {
			((char*)&state)[i] = floor(Random() * 256);
		}
		player = rand() % 5;
		state.handCount[player] = rand() % MAX_HAND;
		state.handCount[player] += 1;
		for(j = 0; j < state.handCount[player]; j++){
			state.hand[player][j] = rand() % 27;
		}
		bonus = rand() % 10;
		//count treasure cards
		for(j = 0; j < state.handCount[player]; j++){
			if(state.hand[player][j] == copper){
				c += 1;
			} else if(state.hand[player][j] == silver){
				s += 1;
			} else if(state.hand[player][j] == gold){
				g += 1;
			}
		}
		//get coin total
		coin_total = c + (s * 2) + (g * 3) + bonus;
		r = updateCoins(player, &state, bonus);
		assert(r == 0);
		//check updateCoins against calculated coin total
		if(state.coins == coin_total){
			printf("Pass: %d copper, %d silver, %d gold, %d bonus = %d coins\n", c, s, g, bonus, coin_total);
		} else {
			printf("Fail: %d copper, %d silver, % d gold, %d bonus. %d coins, returned %d coins\n", c, s, g, bonus, coin_total, state.coins);
		}
	}

	return 0;
}